package com.aaa.hospital.ManagementEnd.controller;


import com.aaa.hospital.ManagementEnd.pojo.ExpenseCalendar;
import com.aaa.hospital.ManagementEnd.pojo.MProfit;
import com.aaa.hospital.ManagementEnd.pojo.Profit;
import com.aaa.hospital.ManagementEnd.pojo.Receipts;
import com.aaa.hospital.ManagementEnd.service.ExpenCalendService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@RequestMapping("/expenCalend")
public class ExpenCalendController {

    @Autowired
    private ExpenCalendService expenCalendService;

    @RequestMapping("/exquery")
    @ResponseBody
        public String exquery(){
        JSONObject json = new JSONObject();
        List<ExpenseCalendar> calendars = expenCalendService.ecQuery();
        Object objData=JSONObject.toJSON(calendars);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",calendars.size());
        json.put("data",objData);
        return json.toJSONString();
    }

    @RequestMapping("/listById")
    @ResponseBody
    public String listById(Integer visid){
        JSONObject json = new JSONObject();
        List<ExpenseCalendar> calendars = expenCalendService.eclistByid(visid);
        Object objData=JSONObject.toJSON(calendars);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",calendars.size());
        json.put("data",objData);
        System.out.println(json+"<==================>");
        return json.toJSONString();
    }

    @RequestMapping(name = "查询利润，生成统计图",value = "/Mprofit",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object getProfit(){
        List<ExpenseCalendar> shops = expenCalendService.selectMProfit();
        MProfit profit=new MProfit();
        for (ExpenseCalendar shop:shops) {
            List<String> x = profit.getX();
            List<Integer> y = profit.getY();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            x.add(sdf.format(shop.getEctime()));
            y.add(shop.getMoney());
            profit.setX(x);
            profit.setY(y);
        }
        return profit;
    }



    @RequestMapping("/etquery")
    @ResponseBody
    public String etquery(){
        JSONObject json = new JSONObject();
        List<ExpenseCalendar> calendars = expenCalendService.etQuery();
        Object objData=JSONObject.toJSON(calendars);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",calendars.size());
        json.put("data",objData);
        return json.toJSONString();
    }

    @RequestMapping("/etlistById")
    @ResponseBody
    public String etlistById(Integer visid){
        JSONObject json = new JSONObject();
        List<ExpenseCalendar> calendars = expenCalendService.etlistByid(visid);
        Object objData=JSONObject.toJSON(calendars);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",calendars.size());
        json.put("data",objData);
        return json.toJSONString();
    }








}
